import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:qaun_ni_dev/pages/active/active_video.dart';
import 'package:qaun_ni_dev/utils/date_time.dart';
import 'package:qaun_ni_dev/provider/active_provider.dart';

class ActiveDetail extends StatelessWidget {
  var activeData;
  ActiveDetail(this.activeData);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('用户动态详情'),
        ),
        body: Stack(
          children: <Widget>[
            _detailContent(context,activeData),
            _optionBtn(context, activeData),
          ],
        ));
  }

  Widget _detailContent(context,activeData) {
    return Container(
        padding: EdgeInsets.only(top: 10, left: 10, right: 10, bottom: 80),
        height: 610,
        child: ListView(
          children: <Widget>[
            Column(
              children: <Widget>[
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('用户id:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${activeData.id}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('用户昵称:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${activeData.userInfo.nickName}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('用户性别:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${activeData.userInfo.sex}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('动态类型:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${activeData.postType == 0? '日常动态':'其他动态'}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding:
                  EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))),
                  child: Row(
                    children: <Widget>[
                      Container(
                        child: Text('动态内容:'),
                        width: 90,
                        margin: EdgeInsets.only(right: 10),
                      ),
                      Container(
                        width: 210,
                        child: Text('${activeData.postContent}'),
                      )
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
                  margin: EdgeInsets.only(bottom: 10),
                  decoration: BoxDecoration(
                      border: Border.all(width: 1, color: Colors.grey),
                      borderRadius: BorderRadius.all(Radius.circular(5))
                  ),
                  child: Column(
                    children: <Widget>[
                      Container(
                        width: 360,
                        child:  Text('用户视频：', textAlign: TextAlign.left,),
                      ),
                      Container(
                        child: Row(
                          children: <Widget>[
                            SizedBox(
                              width: 90,
                            ),
                            InkWell(
                              child: Container(
                                width: 180,
                                child: Image.network(activeData.postCoverUrl),
                              ),
                              onTap: () {
                                Navigator.push(context,MaterialPageRoute(
                                    builder: (context) {
                                      Provider.of<ActiveProvider>(context,listen: false).getActiveVideoUrl(activeData.postVideoUrl);
                                      return ActiveVideoPage();
                                    }
                                ));
                              },
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ],
            )
          ],
        ));
  }

  Widget _optionBtn(context, activeData) {
    return Positioned(
      bottom: 0,
      width: 360,
      height: 80,
      left: 40,
      child: Container(
        alignment: Alignment.center,
        child: Row(
          children: <Widget>[
            Container(
              width: 100,
              height: 40,
              padding: EdgeInsets.only(top: 10, bottom: 10),
              margin: EdgeInsets.only(right: 80),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(40)),
                color: Colors.lightBlue,
              ),
              child: InkWell(
                onTap: () {
                  _agreeActive(context,activeData);
                },
                child: Text(
                  '通过',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            Container(
              width: 100,
              height: 40,
              padding: EdgeInsets.only(top: 10, bottom: 10),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(40)),
                color: Colors.redAccent,
              ),
              child: InkWell(
                onTap: () {
                  _forbidActive(context, activeData);
                },
                child: Text(
                  '拒绝',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _forbidActive(context, activeData) {
    showDialog<Null>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('警告'),
          content: Text('该动态确认拒绝吗？'),
          actions: <Widget>[
            FlatButton(
              child: Text("取消"),
              onPressed: () {
                Navigator.of(context).pop();
              } , //关闭对话框
            ),
            FlatButton(
              child: Text("拒绝"),
              onPressed: () {
                var formData = {
                  'checkResult': 1,
                  'postId': activeData.id,
                  'uId': activeData.userInfo.id
                };
                Provider.of<ActiveProvider>(context,listen: false).isAgreeUserActive(context,formData);
                Navigator.of(context).pop(); //关闭对话框
              },
            ),
          ],
        );
      },
    ).then((val) {
      print(val);
    });
  }

  Widget _agreeActive(context, activeData) {
    showDialog<Null>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('提示'),
          content: Text('该动态确认通过吗？'),
          actions: <Widget>[
            FlatButton(
              child: Text("取消"),
              onPressed: () {
                Navigator.of(context).pop();
              } , //关闭对话框
            ),
            FlatButton(
              child: Text("通过"),
              onPressed: () {
                var formData = {
                  'checkResult': 2,
                  'postId': activeData.id,
                  'uId': activeData.userInfo.id
                };
                Provider.of<ActiveProvider>(context,listen: false).isAgreeUserActive(context,formData);
                Navigator.of(context).pop(); //关闭对话框
              },
            ),
          ],
        );
      },
    ).then((val) {
      print(val);
    });
  }

}
